<?php

namespace Common\Model;
use think\Model;

class UserMoneyHistoryModel extends BaseModel{

	//追加属性
    public $append = [
        'type_name',        //类型
        'f_type_name',      //渠道
        'change_val',
        'amount',
        'ubase',
        'add_time_text',
        'pay_time_text',
	];

    /**
     * 添加时间
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getPayTimeTextAttr($value, $data){
		$text = $data['pay_time'] ? date('Y-m-d H:i:s',$data['pay_time']) : '--';
		return $text;
    }

    public function getChangeValAttr($value, $data){
		return floatval($data['change_val']);
    }

    public function getAmountAttr($value, $data){
		return floatval($data['amount']);
    }

    //子分类数量
    function getFTypeNameAttr($val, $data){
        $type_name = getUtype($data['f_type']);
        return $type_name;
    }

    //上级名称
    function getTypeNameAttr($val, $data){
        $text = '';
        if($data['type']==1){
            $text = '收入';
        }else{
            $text = '支出';
        }
        return $text;
    }

    //搜索
    function _search(){
        $map = [];
        if(I('keyword')){
            $map['remark|uid'] = array('like','%'.I('keyword').'%');
        }
        return $map;
    }



}